package com.epam.tcs.dao.hibernate.impl;

import java.util.List;

import org.hibernate.Session;

import com.epam.tcs.dao.factory.PracticeStatusDAO;
import com.epam.tcs.dao.hibernate.ConnectionFactory;
import com.epam.tcs.dao.hibernate.entities.PracticeStatus;

;

public class PracticeStatusDAOHibernateImpl extends
		ElementDAOHibernateImpl<PracticeStatus> implements PracticeStatusDAO {

	public PracticeStatusDAOHibernateImpl(Class objType) {
		this.objType = objType;
	}

	@Override
	public PracticeStatus getElement(long id) {
		Session session = ConnectionFactory.getOrInitSession();
		PracticeStatus practiceStatus = (PracticeStatus) session.load(objType, id);

		practiceStatus.getJournalPracticeStatuses().get(0);

		session.close();
		return practiceStatus;
	}

	@Override
	public List<PracticeStatus> getAllElements() {
		Session session = ConnectionFactory.getOrInitSession();
		List<PracticeStatus> practiceStatuses = (List<PracticeStatus>) session
				.createQuery("from " + objType.getName()).list();

		for (PracticeStatus practiceStatus : practiceStatuses) {
			practiceStatus.getJournalPracticeStatuses().get(0);
		}

		session.close();
		return practiceStatuses;
	}
}
